class RecordDetailsItem extends ComponentEx {

    private lab_rank: eui.Label;
    private lab_time: eui.Label;
    private btn_play: ButtonEx;
    private btn_share: ButtonEx;

    public constructor() {
        super();
        this.skinName = "RecordDetailsItemSkin";
    }

    childrenCreated() {
        super.childrenCreated();

        if (GameConfig.isPureness) {
            this.btn_share.visible = false;
        }

        this.btn_play.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickHandler, this);
        this.btn_share.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickHandler, this);
    }

    private clickHandler(e: egret.TouchEvent): void {
        switch (e.currentTarget) {
            case this.btn_share:
                Replayer.shareIF.uid = game.player.uid;
                Replayer.shareIF.playback_id = this.data[1].split("#")[1];
                Replayer.shareIF.share_desc = "来自: " + game.player.nick + "   时间: " + this.timeStr;
                Weixin.shareReplay();
                break;
            case this.btn_play:
                game.ReplayType = 0;
                gameManager.socketManager.send(21, { id: this.data[1] });
                break;
        }

    }

    update(data): void {
        if (!data || data.length <= 0) return;

        this.data = data;

        this.lab_time.text = this.timeStr;

        let person: any;

        let item: RecordPlayerItem;

        for (let i = 1; i <= 4; i++) {
            item = this['item_' + i];

            person = game.recordInfos[i - 1];
            if (person) {
                item.update(person);
                item.score = +this.data[+person.pos + 1];
            }
            else {
                item.clean();
            }
        }
    }

    set rank(va: number) {
        this.lab_rank.text = "第" + va + "局";
    }

    private get timeStr() {
        return StringUtils.getYTDByTimestamp(this.data[0] * 1000) + " " + StringUtils.getHMSByTimestamp(this.data[0] * 1000);
    }
}